# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>
# Contributor: Jonne Haß <me@jhass.eu>

pkgname=crystal
pkgver=1.10.1
pkgrel=1
pkgdesc='The Crystal Programming Language'
arch=(loong64 x86_64)
url='https://crystal-lang.org'
license=(Apache)
depends=(gc pcre2 libevent llvm-libs)
makedepends=(libxml2 llvm crystal) # to compile version N we need crystal compiler of N-1 version
checkdepends=(libyaml libxml2 gmp inetutils git)
optdepends=('shards: crystal language package manager'
            'libyaml: For YAML support'
            'gmp: For BigInt support'
            'libxml2: For XML support')
source=(crystal-$pkgver.tar.gz::https://github.com/crystal-lang/crystal/archive/$pkgver.tar.gz)
sha256sums=('f6449ffff519c86383f5e845455f3e6f6b10d6090effab09568f4c7414a8a51b')

build() {
  cd $pkgname-$pkgver

  make release=1 interpreter=1 \
       FLAGS="--release --no-debug" \
       CRYSTAL_CONFIG_PATH="lib:/usr/lib/crystal" \
       CRYSTAL_CACHE_DIR="/tmp/crystal"
  make docs CRYSTAL_CACHE_DIR="/tmp/crystal"
}

check() {
  cd $pkgname-$pkgver
  return # tests require too much RAM, disable it temporary

  make spec CRYSTAL_CACHE_DIR="/tmp/crystal"
}

package() {
  cd $pkgname-$pkgver

  # /usr/bin/crystal                compiled executable
  # /usr/lib/crystal/               compiler src & core libs
  # /usr/share/doc/crystal/api      api docs
  # /usr/share/doc/crystal/samples/ samples

  install -Dm755 ".build/crystal" "$pkgdir/usr/bin/crystal"

  install -dm755 "$pkgdir/usr/lib" "$pkgdir/usr/share/man/man1"
  cp -r src "$pkgdir/usr/lib/crystal"

  install -dm755 "$pkgdir/usr/share/doc/crystal"
  cp -r docs "$pkgdir/usr/share/doc/crystal/api"
  cp -r samples "$pkgdir/usr/share/doc/crystal/"

  install -Dm644 man/crystal.1 "$pkgdir/usr/share/man/man1/"

  install -Dm644 etc/completion.bash "$pkgdir/usr/share/bash-completion/completions/crystal"
  install -Dm644 etc/completion.zsh "$pkgdir/usr/share/zsh/site-functions/_crystal"

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
